package com.token.iot.bratterycharging.gateway.main;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {
	public static final String SHUTDOWN_HOOK_KEY = "dubbo.shutdown.hook";
	private static volatile boolean running = true;

	public static void main(String[] args) {
		final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
				"classpath*:/spring/*Beans.xml");
		context.start();

		if ("true".equals(System.getProperty(SHUTDOWN_HOOK_KEY))) {
			Runtime.getRuntime().addShutdownHook(new Thread() {
				public void run() {
					context.stop();
					context.close();
					synchronized (Main.class) {
						running = false;
						Main.class.notify();
					}
				}
			});
		}

		synchronized (Main.class) {
			while (running) {
				try {
					Main.class.wait();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}
	}
}
